package ar.com.quickmart.classes;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class QuickMartListAdapter extends BaseAdapter {

	private final Context mContext;
	private final List<QuickMartList> mLists;
	
	public QuickMartListAdapter(Context context, List<QuickMartList> lists) {
		super();
		mContext = context;
		mLists = lists;
	}
	
	@Override
	public int getCount() {
		return mLists.size();
	}

	@Override
	public Object getItem(int position) {
		return mLists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return mLists.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		// La vista que contiene el layout de la fila voy a devolver
		View row = convertView;
		
		QuickMartListHolder holder = new QuickMartListHolder();
			
		if(row == null) {
			
			
			
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
			
			holder.txtName = (TextView) row.findViewById(android.R.id.text1);
			
			row.setTag(holder);			
		}
		else {
					holder = (QuickMartListHolder) row.getTag();
		}		

			holder.txtName.setText(mLists.get(position).getName());
			holder.txtName.setTextColor(Color.BLACK);
			
			if(mLists.get(position).getBranch() != null) {
				holder.txtName.setTextColor(Color.parseColor("#FF8000"));
			}
			
		return row;
	}
	
	private static class QuickMartListHolder {
		public TextView txtName;
	}

}
